package com.hyh.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hyh.admin.domain.resources.Resources;
import com.hyh.admin.domain.resources.ResourcesCategory;
import com.hyh.admin.mapper.resources.ResourcesCategoryMapper;
import com.hyh.admin.service.IResourcesCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class ResourcesCategoryServiceImpl implements IResourcesCategoryService {

    @Autowired
    private ResourcesCategoryMapper resourcesCategoryMapper;

    @Override
    public List<Resources> selectResourcesByCategoryName(String name) {
        return resourcesCategoryMapper.selectResourcesByCategoryName(name);
    }

    @Override
    public List<Resources> selectResourcesByCategoryId(Long id) {
        return resourcesCategoryMapper.selectResourcesByCategoryId(id);
    }

    @Override
    public List<ResourcesCategory> selectResourcesByParentId(Long parentId) {
       LambdaQueryWrapper<ResourcesCategory> queryWrapper = new LambdaQueryWrapper<>();
       queryWrapper.eq(ResourcesCategory::getParentId, parentId);
       return resourcesCategoryMapper.selectList(queryWrapper);
    }



    @Override
    public int deleteResourcesCategoryById(Long id) {
        return resourcesCategoryMapper.deleteById(id);
    }

    @Override
    public int insert(ResourcesCategory resourcesCategory) {
        return resourcesCategoryMapper.insert(resourcesCategory);
    }

    @Override
    public List<ResourcesCategory> selectSortList(ResourcesCategory resourcesCategory) {
        LambdaQueryWrapper<ResourcesCategory> queryWrapper = new LambdaQueryWrapper<>();
        //queryWrapper.eq(ResourcesCategory::getParentId, resourcesCategory.getParentId());
        queryWrapper.orderByAsc(ResourcesCategory::getCreateTime);
        return resourcesCategoryMapper.selectList(queryWrapper);
    }
}
